package com.jsgt.greekfire.ui.coin.ordermanagement

import android.widget.TextView
import androidx.viewpager.widget.ViewPager
import com.fhx.core.base.BaseActivity
import com.fhx.core.base.BaseFragment
import com.google.android.material.tabs.TabLayout
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.trading.adapter.PagerAdapter
import kotlinx.android.synthetic.main.activity_order_management.*

class OrderManagementActivity : BaseActivity() {
    private val fragments: MutableList<BaseFragment> = ArrayList()
    private var coinFragment: HistoricalOrdersFragment? = null
    var tvTitle: TextView? = null
    override fun getLayoutId(): Int = R.layout.activity_order_management
    override fun main() {
        initTab()
        tvTitle = findViewById(R.id.title_tv)
        tvTitle?.text =resources.getString(R.string.orders)
    }


    private fun initTab() {
        var item = resources.getStringArray(R.array.historical_orders_list)
        val tabs = java.util.ArrayList<String>()
        for (i in item.indices) {
            tabs.add(item[i])
            coinFragment = HistoricalOrdersFragment.newInstance(item[i])
            fragments.add(coinFragment!!)
        }

        tabOrderManagement.tabMode = TabLayout.MODE_FIXED
        tabOrderManagement.setupWithViewPager(vpOrderManagement)
        vpOrderManagement.adapter = PagerAdapter(
            supportFragmentManager,
            fragments,
            tabs
        )
        vpOrderManagement.currentItem = 0
        vpOrderManagement.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {
            }

            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
            }
        })
    }

}